import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

import Layout from "@/layout";
import orderRouter from "@/router/modules/order";
import bulkRouter from "@/router/modules/bulk";
import purchasingRouter from "@/router/modules/purchasing";
import warehouseRouter from "@/router/modules/warehouse";
import sortingRouter from "@/router/modules/sorting";
import commodityRouter from "@/router/modules/commodity";
import menuRouter from "@/router/modules/menu";
import userRouter from "@/router/modules/user";
import marketingRouter from "@/router/modules/marketing";
import financialRouter from "@/router/modules/financial";
import reportRouter from "@/router/modules/report";
import shopRouter from "@/router/modules/shop";
import kitchenRouter from "@/router/modules/kitchen";
import distributionRouter from "@/router/modules/distribution";
import globalRouter from "@/router/modules/global";
import tplusRouter from "@/router/modules/tplus";

export const constantRoutes = [
  // {
  //   path: "/ordertem",
  //   component: () => import("@/views/order/orderPrint"),
  //   forget: true,
  //   hidden: true
  // },
  {
    path: "/login",
    component: () => import("@/views/login/new_login.vue"),
    forget: true,
    hidden: true
  },
  {
    path: "/process",
    component: () => import("@/views/index/process.vue"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    forget: true,
    hidden: true
  },
  {
    path: "/bigdata",
    component: () => import("@/views/bigData/bigData.vue"),
    forget: true,
    hidden: true
  },
  {
    path: "/fjscreen",
    component: () => import("@/views/fjscreen/index.vue"),
    forget: true,
    hidden: true
  },
  {
    path: "/demo",
    component: () => import("@/views/bigData/demo.vue"),
    forget: true,
    hidden: true
  },
  // 编辑通用模板
  {
    path: "/print/ordertemplate",
    component: Layout,
    name: "orderprint",
    component: () => import("@/views/global/print_order/Main"),
    forget: true,
    hidden: true
  },
  // 新增模板
  {
    path: "/print/addOrderTemplate",
    component: Layout,
    name: "addOrderPrint",
    component: () => import("@/views/global/add_print_order/Main"),
    forget: true,
    hidden: true
  },
  {
    path: "/global/delivery/index",
    component: Layout,
    name: "delivery",
    component: () =>
      import("@/views/global/delivery/index.vue"),
    hidden: true,
    forget: true,
  },
  {
    path: "/print/sortnotetemplate",
    component: Layout,
    name: "sortprint",
    component: () => import("@/views/global/print_sort_note/Main"),
    forget: true,
    hidden: true
  },
  {
    path: "/print/406",
    component: Layout,
    name: "orderprint_copy",
    component: () => import("@/views/global/print_order_copy/Main"),
    forget: true,
    hidden: true
  },
  {
    path: "/commission/pay",
    name: "commission_pay",
    component: () => import("@/views/index/commissionPay"),
    forget: true,
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/index",
    forget: true,
    hidden: true,
    children: [
      {
        path: "index",
        name: "index",
        // component: () => import("@/views/index/index_copy"),
        component: () => import("@/views/index/index"),

        meta: { title: "首页", icon: "index" }
      },
      {
        path: "/moretender",
        name: "moretender",
        component: () => import("@/views/index/components/moreTender.vue"),
        meta: { title: "招标信息", icon: "index" }
      },
      {
        path: "/morefeedback",
        name: "morefeedback",
        component: () => import("@/views/index/components/moreFeedBack.vue"),
        meta: { title: "更多反馈", icon: "index" }
      },
      {
        path: "/kitchen",
        name: "kitchen",
        component: () => import("@/views/kitchen/kitchenCatering.vue"),
        meta: { title: "应用管理", icon: "index" }
      }
    ]
  },
  orderRouter,
  // bulkRouter,
  purchasingRouter,
  warehouseRouter,
  sortingRouter,
  commodityRouter,
  userRouter,
  menuRouter,
  marketingRouter,
  financialRouter,
  reportRouter,
  shopRouter,
  // kitchenRouter,
  distributionRouter,
  globalRouter,
  tplusRouter,
  {
    path: "/cost/index",
    name: "cost",
    component: () => import("@/views/cost/index"),
    forget: true,
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", forget: true, hidden: true }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  window.location.reload();
  router.matcher = newRouter.matcher;
}
export default router;
